#include<stdio.h>
struct Students
{
    int gender;
    char name[9];
};

typedef struct Students S;

int main()
{
    int N, i, j;
    scanf("%d", &N);
    
    S data[N];

    for(i = 0; i < N; i ++)
    {
        scanf("%d %s", &data[i].gender, data[i].name);
    }

    i = 0;
    j = N - 1;
    while(i < j)
    {
        if(data[i].gender != data[j].gender && data[j].gender != 3)
        {
            printf("%s %s\n", data[i].name, data[j].name);
            data[j].gender = 3;
            i++;
            j = N - 1;
            continue;
        }
        j--;
    }

    return 0;
}

